Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Get location of player spawn point on fly

  1. #1

    Default Get location of player spawn point on fly

    Is there a way to get something like $player.origin when a player spawns and when a player dies? The goal is to check if a player died within x units of his spawn within x seconds, then punish local.attacker. I was looking for something that could be easily applied to any map (aka not pulling playerinfo cords from every bsp to get possible coords of spawn points).

    Was maybe thinking something like this? (go to the killed thread. that's where I'm completely lost)

    Main:
    
    	if(level.protect_punish)
    	end
    
    	level.protect_punish = 1
    	local.result = registerev "kill" global/protectpunish.scr::killed
    
    	self.protected_punish = 1
    	self.protecting_punish = 1
    
    	local.timer_old_punish = 10;
    	local.timer_punish = ( local.timer_old_punish * 100 );
    	local.time_punish = 0;
    	local.allowed_time_old_punish = 1;
    	local.allowed_time_punish = ( local.allowed_time_old_punish * 100 );
    
    
    	self thread check_death_punish
    
    	while( (self != NIL) || (self != NULL) || (self.protecting_punish == 1) )
    	{
    		if( (local.time_punish == local.timer_punish) || (self.fireheld == 1) )
    		{
    			if(local.time_punish > local.allowed_time_punish)
    				{
    					self.protecting_punish = 0
    					end
    				}
    		}
    
    		wait 0.01;
    		local.time_punish ++;
    	}
    
    end
    
    check_death_punish:
    
    	local.a = 1
    	local.team = self.dmteam
    
    	while(local.a)
    	{
    		if(self)
    		{
    			if( (self.dmteam != local.team) || (self.health <= 0) )
    			{
    				self.protected_punish = 0
    				local.a = 0
    			}
    		}
    		else
    		{
    			local.a = 0
    		}
    		wait 1
    	}
    
    end
    
    
    killed local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location local.player:
    
    	if(local.player.classname == "Player" && local.attacker.classname == "Player")
    	{
        // These are the lines where it is obvious I have no idea what I'm doing ---
    		local.spawnedat = $player.origin // does this pull a cord from spawn location?
    		local.diedat = local.position // position takes vector pos, does that mean where you died??
    
    		local.safezone = spawn trigger_multiple // do you have to spawn a trigger to set the size of something? logically not sure how else it would work
    		local.safezone.origin = local.spawnedat // how do I tell the script to take local.player.spawnedat? I only want to see where the dead player spawned to reference
    		local.safezone setsize ( -200 -200 -10 ) ( 200 200 10 )
    	// --------------------------
    		if(local.player.protected_punish == 1) && local.dieat istouching local.safezone // positive this isn't correct syntax. It's the only way I know how to convey the idea in my head though. Hopefully someone who knows what they're doing can help put this into a syntax that actually works :/
    		{
    			local.attacker iprint "Spawn killing is not allowed"
    			local.attacker=parm.other // also, does this even work? I have a feeling this is incorrect.
    			local.attacker hurt 50
    			local.attacker takeall
    			local.attacker give models/weapons/colt45.tik
    			local.attacker useweaponclass pistol
    		}
    	}
    
    end
    Last edited by [cB]SplatterGuts; June 25th, 2017 at 12:15 PM.

  2. #2
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,567

    Default

    $player.origin is the coordinates of the player. but it should be local.player.origin.
    to get where the player spawned at, use the spawned event and save it to a variable like local.player.spawn_orig = local.player.origin.
    the hackish way to get the distance is by :
    local.dist = vector_length(vector_subtract(local.player.spawn_orig-local.player.orig))
    because in solid geometry: the distance between two 3d points is the square root of (x1-x2)^2+(y1-y2)^2+(z1-z2)^2. which is the length of subtracting the two points.

  3. #3

    Default

    Awesome. That's super useful. Just wondering how I incorporate the local.dist you've included? If I use as is, I'm just establishing the "safezone" where if a player dies within "local.dist", the punishments happen, right?

    something like if(local.dist) < (200 200 200){ local.attacker hurt 100 blah blah blah }

  4. #4
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,567

    Default

    Quote Originally Posted by [cB]SplatterGuts View Post
    Awesome. That's super useful. Just wondering how I incorporate the local.dist you've included? If I use as is, I'm just establishing the "safezone" where if a player dies within "local.dist", the punishments happen, right?

    something like if(local.dist) < (200 200 200){ local.attacker hurt 100 blah blah blah }
    local.dist is not a vector, it is a number. the distance between the player and his spawn point.

  5. #5

    Default

    Why you dont just create a spawnprotection area with a trigger? is more simple.

  6. #6

    Default

    DK, can the trigger be made in reference to spawn points, or does it have to be hard coded per map? If I only had 10 maps on my server, I'd totally do that. But we run 200+ custom maps, so that's a bit much lol. I'm totally open to suggestions though!

    Ryback, can you tell me where I'm wrecking this part of the script?

    killed local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location local.player:
    
    	if(local.player.classname == "Player" && local.attacker.classname == "Player")
    	{
    
    		local.dist = vector_length(vector_subtract(local.player.spawn_orig-local.player.origin))
    			if((local.player.protecting == 1) && (local.dist < 200))
    		{
    			local.attacker iprint "Spawn killing is not allowed"
    			//local.attacker hurt 50
    			//local.attacker takeall
    			//local.attacker give models/weapons/colt45.tik
    			//local.attacker useweaponclass pistol
    		}
    	}
    
    end



    --

    Full script so far;

    Main:
    
      /////////////////////////////////////////////////////////////////////////
      //If player already has been protected.
      if(self.protected)
        end
    
    	local.result = registerev "spawn" global/spawn_protect.scr::spawned
    	local.result = registerev "kill" global/spawn_protect.scr::killed
    
    
      /////////////////////////////////////////////////////////////////////////
      //If not, tell script to give them some.
      self.protected = 1;
      self.protecting = 1;
    
      /////////////////////////////////////////////////////////////////////////
      //Make the player invincible.
      self stufftext "locationprint 500 50 Punish-On"
      self nodamage;
    
      /////////////////////////////////////////////////////////////////////////
      //Sort out the protection time.
      local.timer_old = 5;
      local.timer = ( local.timer_old * 100 );
      local.time = 0;
      local.allowed_time_old = 1;
      local.allowed_time = ( local.allowed_time_old * 100 );
    
      /////////////////////////////////////////////////////////////////////////
      //Apply light.
      self light 0 1 0 40;
    
      /////////////////////////////////////////////////////////////////////////
      //Detect death/repawn.
      self thread check_death
    
      /////////////////////////////////////////////////////////////////////////
      //While the player exists and hasn't completed the spawn protection.
      while( (self != NIL) || (self != NULL) || (self.protecting == 1) ) {
        /////////////////////////////////////////////////////////////////
        //If the player is shooting OR the protection time has ended,
        //disable the protection.
        if( (local.time == local.timer) || (self.fireheld == 1) ) {
          if(local.time > local.allowed_time) {
            self.protecting = 0;
            self takedamage;
            self lightOff;
    		self stufftext "locationprint 500 50 Punish-Off"
    
            end
          }
        }
        wait 0.01;
        ///////////////////////////////////////////////////////////////////////
        //Add to the timer that counts how many seconds of protection the
        //player has had.
        local.time ++;
      }
    
    end
    
    check_death:
    
      local.a = 1;
      local.team = self.dmteam;
    
      while(local.a) {
        if(self) {
          if( (self.dmteam != local.team) || (self.health <= 0) ) {
            ///////////////////////////////////////////////////////////////////
            //Player died.
            self.protected = 0;
            local.a = 0;
          }
        } else {
          /////////////////////////////////////////////////////////////////////
          //Player left the server.?
          local.a = 0;
        }
        wait 1;
      }
    
    end
    
    
    spawned local.player:
    local.player.spawn_orig = local.player.origin
    //iprintln "origin noted"
    end
    
    
    killed local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location local.player:
    
    	if(local.player.classname == "Player" && local.attacker.classname == "Player")
    	{
    
    		local.dist = vector_length(vector_subtract(local.player.spawn_orig-local.player.origin))
    
    		if((local.player.protecting == 1) && (local.dist < 200))
    		{
    			local.attacker iprint "Spawn killing is not allowed"
    			//local.attacker=parm.other
    			//local.attacker hurt 50
    			//local.attacker takeall
    			//local.attacker give models/weapons/colt45.tik
    			/local.attacker useweaponclass pistol
    		}
    	}
    
    end
    Last edited by [cB]SplatterGuts; June 25th, 2017 at 02:05 PM.

  7. #7
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,567

    Default

    where and how do u exec it ?

  8. #8

    Default

    dmprecache.scr:

    level waittill spawn
    exec global/spawn_protect.scr

    I hashed out everything and started one at a time adding stuff back in. All works until I get to the "killed" thread. Something there stops the rest of the script from working. I checked all my other scripts, not using the killed event anywhere else (I remember PE saying you'll have issues if you try running the same event from two scripts).

  9. #9

    Default

    I think the killed event dont work because you overwriting the first variable with the spawn event, needs to be independent like this:
    Main:
    
      /////////////////////////////////////////////////////////////////////////
      //If player already has been protected.
      if(self.protected)
        end
    
    	local.result = registerev "spawn" global/spawn_protect.scr::spawned
    	local.result_2 = registerev "kill" global/spawn_protect.scr::killed

  10. #10

    Default

    Thanks for the suggestion. I've used multiple local.result lines in the past, but I changed it here to see if it was causing issues. Initially it didn't resolve anything, but I noticed a commented line only had one / instead of two, so I added the second / and things started working better. Still not completely operational though. Here's the current killed thread:

    killed local.attacker local.player:
    
     iprintln "killed working"
     local.player.died_orig = local.player.origin
    
    	if(local.player.classname == "Player" && local.attacker.classname == "Player")
    	{
    		iprintln "killed working inside"
    		local.dist = vector_length(vector_subtract(local.player.spawn_orig-local.player.died_orig))
    		local.player iprintln ("Distance: " + local.dist)
    
    //		if((local.player.protecting == 1) && (local.dist < 200))
    //		{
    //			local.attacker iprint "Spawn killing is not allowed"
    //			local.attacker=parm.other
    //			local.attacker hurt 50
    //			local.attacker takeall
    //			local.attacker give models/weapons/colt45.tik
    //			local.attacker useweaponclass pistol
    //		}
    	}
    
    end


    I can't get the lines that print the distance to show up. I just want this for testing purposes so I can see that things are actually working, but this seems to be the current break point.

    Full script for reference:

    Main:
    
      /////////////////////////////////////////////////////////////////////////
      //If player already has been protected.
      if(self.protected)
        end
    
    	local.result = registerev "spawn" global/spawn_protect.scr::spawned
    	local.result_2 = registerev "kill" global/spawn_protect.scr::killed
    
    
      /////////////////////////////////////////////////////////////////////////
      //If not, tell script to give them some.
      self.protected = 1;
      self.protecting = 1;
    
      /////////////////////////////////////////////////////////////////////////
      //Make the player invincible.
      self stufftext "locationprint 500 50 Punish-On"
      //self nodamage;
    
      /////////////////////////////////////////////////////////////////////////
      //Sort out the protection time.
      local.timer_old = 5;
      local.timer = ( local.timer_old * 100 );
      local.time = 0;
      local.allowed_time_old = 1;
      local.allowed_time = ( local.allowed_time_old * 100 );
    
      /////////////////////////////////////////////////////////////////////////
      //Apply light.
      self light 0 1 0 40;
    
      /////////////////////////////////////////////////////////////////////////
      //Detect death/repawn.
      self thread check_death
    
      /////////////////////////////////////////////////////////////////////////
      //While the player exists and hasn't completed the spawn protection.
      while( (self != NIL) || (self != NULL) || (self.protecting == 1) ) {
        /////////////////////////////////////////////////////////////////
        //If the player is shooting OR the protection time has ended,
        //disable the protection.
        if( (local.time == local.timer) || (self.fireheld == 1) ) {
          if(local.time > local.allowed_time) {
            self.protecting = 0;
           // self takedamage;
            self lightOff;
    		self stufftext "locationprint 500 50 Punish-Off"
    
            end
          }
        }
        wait 0.01;
        ///////////////////////////////////////////////////////////////////////
        //Add to the timer that counts how many seconds of protection the
        //player has had.
        local.time ++;
      }
    
    end
    
    check_death:
    
      local.a = 1;
      local.team = self.dmteam;
    
      while(local.a) {
        if(self) {
          if( (self.dmteam != local.team) || (self.health <= 0) ) {
            ///////////////////////////////////////////////////////////////////
            //Player died.
            self.protected = 0;
            local.a = 0;
          }
        } else {
          /////////////////////////////////////////////////////////////////////
          //Player left the server.?
          local.a = 0;
        }
        wait 1;
      }
    
    end
    
    
    spawned local.player:
    local.player.spawn_orig = local.player.origin
    iprintln ("origin noted: " + local.player.spawn_orig)
    end
    
    
    killed local.attacker local.player:
    
     iprintln "killed working"
     local.player.died_orig = local.player.origin
    
    	if(local.player.classname == "Player" && local.attacker.classname == "Player")
    	{
    		iprintln "killed working inside"
    		local.dist = vector_length(vector_subtract(local.player.spawn_orig-local.player.died_orig))
    		local.player iprintln ("Distance: " + local.dist)
    
    //		if((local.player.protecting == 1) && (local.dist < 200))
    //		{
    //			local.attacker iprint "Spawn killing is not allowed"
    //			local.attacker=parm.other
    //			local.attacker hurt 50
    //			local.attacker takeall
    //			local.attacker give models/weapons/colt45.tik
    //			local.attacker useweaponclass pistol
    //		}
    	}
    
    end

    --- edit

    Made a few adjustments. Looks like I'm not currently setting local.player.died_orig, it prints NIL when I do this in the script...
    NIL for local.player.died_orig and local.dist

    killed local.attacker local.player:
    
     local.player.died_orig = local.player.origin
     iprintln ("killed working: " + local.player.died_orig)
     wait .1
    
    
    	//if(local.player.classname == "Player" && local.attacker.classname == "Player")
    	//{
    		//iprintln "killed working inside"
    		wait .1
    		local.dist = vector_length(vector_subtract(local.player.spawn_orig-local.player.died_orig))
    		iprintln ("Distance: " + local.dist)
    
    //		if((local.player.protecting == 1) && (local.dist < 200))
    //		{
    //			local.attacker iprint "Spawn killing is not allowed"
    //			local.attacker=parm.other
    //			local.attacker hurt 50
    //			local.attacker takeall
    //			local.attacker give models/weapons/colt45.tik
    //			local.attacker useweaponclass pistol
    //		}
    	//}
    
    end
    Last edited by [cB]SplatterGuts; June 25th, 2017 at 03:42 PM.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •